<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <script src="./node_modules/axios/dist/axios.min.js"></script>
    <title>Document</title>
    <style>
      body {
        margin: 0;
        padding: 50px;
      }
    </style>
  </head>
  <body>
    <h1>添加用户</h1>

    <label for="username">用户名:</label>
    <input type="text" id="username" />
    <br />
    <label for="password">用户名:</label>
    <input type="text" id="password" />
    <br />
    <button type="button">提交</button>
  </body>
  <script>
    //获取提交按钮,添加点击事件
    document.querySelector('button').addEventListener('click',function(){
      //这里没有使用表单(from)去收集和提交数据,需要自己获取并提交数据
      //获取用户名和密码
      const username = document.querySelector('#username').value
      const password = document.querySelector('#password').value

      //发送post请求
      axios({
        url:'http://localhost:3000/users',
        method:'post',
        data:{username:username,password:password}
      }).then(() => {
        //跳转到首页
        location.href = './index.html'
      })
    })
  </script>
</html>
